#!/bin/bash

echo_supervisord_conf > /etc/supervisord.conf
export PYTHONOPTIMIZE=1

cat > /etc/supervisord.conf << EOF
[unix_http_server]
file=/tmp/supervisor.sock   

[supervisord]
logfile=/data/Scripts/logs/supervisord.log 
logfile_maxbytes=50MB        
logfile_backups=10           
loglevel=info                
pidfile=/var/run/supervisord.pid 
nodaemon=false               
minfds=1024                  
minprocs=200      
           
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]
serverurl=unix:///tmp/supervisor.sock

[program:getmq]
command=/usr/local/bin/python3.6 /data/Scripts/MqGet.py
directory=/data/Scripts/
stdout_logfile=/data/Scripts/logs/MqGet.log
autostart=true
autorestart=true
redirect_stderr=true
stopsignal=QUIT
numprocs=1

[program:wifi]
command=/usr/local/bin/python3.6 /data/Scripts/PasswdChange.py
directory=/data/Scripts
stdout_logfile=/data/Scripts/logs/PasswdChange.log
autostart=true
autorestart=true
redirect_stderr=true
stopsignal=QUIT
numprocs=1

[program:select]
command=/usr/local/bin/python3.6 /data/Scripts/NameSelect.py
directory=/data/Scripts
stdout_logfile=/data/Scripts/logs/NameSelect.log
autostart=true
autorestart=true
redirect_stderr=true
stopsignal=QUIT
numprocs=1
EOF
supervisord -c /etc/supervisord.conf
sleep 3

/usr/local/bin/python3.6 /data/Scripts/main.py
